﻿using Microsoft.VisualStudio.TestTools.UnitTesting;
using Asistente.Managers;
using Asistente.Model.Representation;

namespace Asistente.Test
{
    [TestClass]
    public class UseCaseManagerTest
    {

        protected void Reset()
        {
            Numerator.Instance.Reset();
        }

        [TestMethod]
        public void TestGetLogin()
        {
            Reset();
            Entity user = new Entity();
            user.Name = "User";

            UseCase login = UseCaseManager.Instance.NewUseCase(UseCasePattern.Login, user);

            Assert.IsNotNull(login.Name);
            Assert.AreEqual("Login1", login.Name);

            // Has only one screen
            Assert.IsTrue(login.Screens.Count == 1);

            // The screen has only one screen
            Assert.IsTrue(login.Screens[0].Panels.Count == 1);
            Assert.AreEqual("Form1",login.Screens[0].Panels[0].Name);

            // The panel has two patterns control
            Assert.IsTrue(login.Screens[0].Panels[0].Controls.Count == 2);

            // And they are two palin text input 
            Assert.AreEqual(login.Screens[0].Panels[0].Controls[0].Quantity, 2);
            Assert.AreEqual(login.Screens[0].Panels[0].Controls[0].ControlPattern, ControlPattern.PlainTextInput);

            // And one check box
            Assert.AreEqual(login.Screens[0].Panels[0].Controls[1].Quantity, 1);
            Assert.AreEqual(login.Screens[0].Panels[0].Controls[1].ControlPattern, ControlPattern.CheckBox);

        }
        [TestMethod]
        public void TestGetPasswordChange()
        {
            Reset();
            Entity user = new Entity();
            user.Name = "User";

            UseCase passChange = UseCaseManager.Instance.NewUseCase(UseCasePattern.PasswordChange,user);

            Assert.IsNotNull(passChange.Name);
            Assert.AreEqual(passChange.Name, "PasswordChange1");

            // Has only one screen
            Assert.IsTrue(passChange.Screens.Count == 1);

            // The screen has only one screen
            Assert.IsTrue(passChange.Screens[0].Panels.Count == 1);
            Assert.AreEqual("Form1",passChange.Screens[0].Panels[0].Name);

            // The panel has one patterns control
            Assert.IsTrue(passChange.Screens[0].Panels[0].Controls.Count == 1);

            // And they are three palin text input 
            Assert.AreEqual(5,passChange.Screens[0].Panels[0].Controls[0].Quantity);
            Assert.AreEqual(passChange.Screens[0].Panels[0].Controls[0].ControlPattern, ControlPattern.PlainTextInput);

        }
        [TestMethod]
        public void TestGetWorkWith()
        {
            Reset();
            Entity master = new Entity();
            master.Name = "User";
            
            UseCase ww = UseCaseManager.Instance.NewUseCase(UseCasePattern.WorkWith, master);

            Assert.IsNotNull(ww.Name);
            Assert.AreEqual(ww.Name, "WorkWith1");

            Assert.IsTrue(ww.Screens.Count == 1); // Has only one screen
            
            Assert.IsTrue(ww.Screens[0].Panels.Count == 1); // The screen has one panel grid)
            Assert.AreEqual("Grid1", ww.Screens[0].Panels[0].Name);

            Assert.IsTrue(ww.Screens[0].Panels[0].Controls.Count == 1);
            Assert.IsTrue(ww.Screens[0].Panels[0].Controls[0].Quantity == 5);
            Assert.AreEqual(ww.Screens[0].Panels[0].Controls[0].ControlPattern, ControlPattern.PlainTextInput);
         }

        [TestMethod]
        public void TestGetNew()
        {
            Reset();
            Entity user = new Entity();
            user.Name = "User";

            UseCase create = UseCaseManager.Instance.NewUseCase(UseCasePattern.New,user);//type 1 

            Assert.IsNotNull(create.Name);
            Assert.AreEqual("New1",create.Name);

            // Has only one screen
            Assert.IsTrue(create.Screens.Count == 1);

            // The screen has one panel
            Assert.IsTrue(create.Screens[0].Panels.Count == 1);
            Assert.AreEqual("Form1", create.Screens[0].Panels[0].Name);

            // The first panel has one control pattern
            Assert.IsTrue(create.Screens[0].Panels[0].Controls.Count == 1);

            // And they are five plain text input 
            Assert.AreEqual(create.Screens[0].Panels[0].Controls[0].Quantity, 5);
            Assert.AreEqual(create.Screens[0].Panels[0].Controls[0].ControlPattern, ControlPattern.PlainTextInput);


            create = UseCaseManager.Instance.NewUseCase(UseCasePattern.New, user);//type 2 

            Assert.IsNotNull(create.Name);
            Assert.AreEqual("New2", create.Name);

            // Has only one screen
            Assert.IsTrue(create.Screens.Count == 1);

            // The screen has two screens
            Assert.IsTrue(create.Screens[0].Panels.Count == 1);
            Assert.AreEqual("Form2", create.Screens[0].Panels[0].Name);

            // The first panel has one control pattern
            Assert.IsTrue(create.Screens[0].Panels[0].Controls.Count == 1);

            // And they are five plain text input 
            Assert.AreEqual(create.Screens[0].Panels[0].Controls[0].Quantity, 5);
            Assert.AreEqual(create.Screens[0].Panels[0].Controls[0].ControlPattern, ControlPattern.PlainTextInput);
        }

        [TestMethod]
        public void TestGetNewComplex()
        {
            Reset();
            Entity master = new Entity();
            master.Name = "Master";

            Entity detail = new Entity();
            detail.Name = "Detail";

            UseCase createComplex = UseCaseManager.Instance.NewUseCase(UseCasePattern.New ,master, detail, UseCaseComplexity.Complex, UseCaseCardinality.One, UseCaseLayout.TwoPanels);

            Assert.IsNotNull(createComplex.Name);
            Assert.AreEqual("New1",createComplex.Name);

            // Has only one screen
            Assert.IsTrue(createComplex.Screens.Count == 1);

            // The screen has two panels
            Assert.IsTrue(createComplex.Screens[0].Panels.Count == 2);
            Assert.AreEqual("Form1", createComplex.Screens[0].Panels[0].Name);
            Assert.AreEqual("Master", ((EditablePanel)createComplex.Screens[0].Panels[0]).Entity.Name);

            Assert.AreEqual("Grid1", createComplex.Screens[0].Panels[1].Name);//Error de Assert.AreEqual. Se esperaba <Grid2>, pero es <Grid1>.
            Assert.AreEqual("Detail", ((EditablePanel)createComplex.Screens[0].Panels[1]).Entity.Name);


            // The first panel has one control pattern
            Assert.IsTrue(createComplex.Screens[0].Panels[0].Controls.Count == 1);

            // And they are five plain text input 
            Assert.AreEqual(createComplex.Screens[0].Panels[0].Controls[0].Quantity, 5);
            Assert.AreEqual(createComplex.Screens[0].Panels[0].Controls[0].ControlPattern, ControlPattern.PlainTextInput);


            // The second panel has one control pattern
            Assert.IsTrue(createComplex.Screens[0].Panels[1].Controls.Count == 1);

            // And they are five plain text input 
            Assert.AreEqual(5,createComplex.Screens[0].Panels[1].Controls[0].Quantity);
            Assert.AreEqual(createComplex.Screens[0].Panels[1].Controls[0].ControlPattern, ControlPattern.PlainTextInput);


            createComplex = UseCaseManager.Instance.NewUseCase(UseCasePattern.New, master, detail, UseCaseComplexity.Complex, UseCaseCardinality.Many, UseCaseLayout.TwoPanels);

            Assert.IsNotNull(createComplex.Name);
            Assert.AreEqual("New2", createComplex.Name);

            // Has only one screen
            Assert.IsTrue(createComplex.Screens.Count == 1);

            // The screen has two panel
            Assert.IsTrue(createComplex.Screens[0].Panels.Count == 2);

            Assert.AreEqual("Grid2", createComplex.Screens[0].Panels[0].Name);
            Assert.AreEqual("Master", ((EditablePanel)createComplex.Screens[0].Panels[0]).Entity.Name);

            Assert.AreEqual("Grid3", createComplex.Screens[0].Panels[1].Name);
            Assert.AreEqual("Detail", ((EditablePanel)createComplex.Screens[0].Panels[1]).Entity.Name);
            //Assert.AreEqual("Child", ((EditablePanel)createComplex.Screens[0].Panels[0]).Entity.Name);


            // The first panel has one control pattern
            Assert.IsTrue(createComplex.Screens[0].Panels[0].Controls.Count == 1);

            // And they are five plain text input 
            Assert.AreEqual(createComplex.Screens[0].Panels[0].Controls[0].Quantity, 5);
            Assert.AreEqual(createComplex.Screens[0].Panels[0].Controls[0].ControlPattern, ControlPattern.PlainTextInput);


            // The second panel has one control pattern
            Assert.IsTrue(createComplex.Screens[0].Panels[1].Controls.Count == 1);

            // And they are five plain text input 
            Assert.AreEqual(createComplex.Screens[0].Panels[1].Controls[0].Quantity, 5);
            Assert.AreEqual(createComplex.Screens[0].Panels[1].Controls[0].ControlPattern, ControlPattern.PlainTextInput);

        }

        [TestMethod]
        public void TestGetSearch()
        {
            Reset();
            Entity user = new Entity();
            user.Name = "User";

            UseCase search = UseCaseManager.Instance.NewUseCase(UseCasePattern.Search, user);

            Assert.IsNotNull(search.Name);
            Assert.AreEqual( "Search1",search.Name);

            // Has only one screen
            Assert.IsTrue(search.Screens.Count == 1);

            // The screen has two screens
            Assert.IsTrue(search.Screens[0].Panels.Count == 2);
            Assert.AreEqual("Filter1", search.Screens[0].Panels[0].Name);
            Assert.AreEqual("User", ((EditablePanel)search.Screens[0].Panels[0]).Entity.Name);

            Assert.AreEqual("Grid1", search.Screens[0].Panels[1].Name);//exp 2-5
            Assert.AreEqual("User", ((EditablePanel)search.Screens[0].Panels[1]).Entity.Name);


            // The first panel has one control pattern
            Assert.IsTrue(search.Screens[0].Panels[0].Controls.Count == 1);

            // And they are five plain text input 
            Assert.AreEqual(search.Screens[0].Panels[0].Controls[0].Quantity, 3);
            Assert.AreEqual(search.Screens[0].Panels[0].Controls[0].ControlPattern, ControlPattern.PlainTextInput);


            // The second panel has one control pattern
            Assert.IsTrue(search.Screens[0].Panels[1].Controls.Count == 1);

            // And they are five plain text input 
            Assert.AreEqual(search.Screens[0].Panels[1].Controls[0].Quantity, 5);
            Assert.AreEqual(search.Screens[0].Panels[1].Controls[0].ControlPattern, ControlPattern.PlainTextOutput);

        }

        [TestMethod]
        public void TestGetList()
        {
            Reset();
            Entity user = new Entity();
            user.Name = "User";

            UseCase list = UseCaseManager.Instance.NewUseCase(UseCasePattern.List,user);

            Assert.IsNotNull(list.Name);
            Assert.AreEqual("List1", list.Name);

            // Has only one screen
            Assert.IsTrue(list.Screens.Count == 1);

            // The screen has one panel
            Assert.IsTrue(list.Screens[0].Panels.Count == 1);
            Assert.AreEqual("Report1", list.Screens[0].Panels[0].Name);
            
            // The panel has one control pattern
            Assert.IsTrue(list.Screens[0].Panels[0].Controls.Count == 1);

            // And they are five plain text input 
            Assert.AreEqual(list.Screens[0].Panels[0].Controls[0].Quantity, 5);
            Assert.AreEqual(list.Screens[0].Panels[0].Controls[0].ControlPattern, ControlPattern.PlainTextOutput);
        }

        [TestMethod]
        public void TestGetConfiguration()
        {
            Reset();
            Entity configuration = new Entity();
            configuration.Name = "Configuration";

            UseCase configUseCase = UseCaseManager.Instance.NewUseCase(UseCasePattern.Configuration, configuration);

            Assert.IsNotNull(configUseCase.Name);
            Assert.AreEqual("Configuration1", configUseCase.Name);

            // Has only one screen
            Assert.IsTrue(configUseCase.Screens.Count == 1);

            // The screen has only one screen
            Assert.IsTrue(configUseCase.Screens[0].Panels.Count == 1);
            Assert.AreEqual("Form1", configUseCase.Screens[0].Panels[0].Name);

            // The panel has two patterns control
            Assert.IsTrue(configUseCase.Screens[0].Panels[0].Controls.Count == 5);

            // And they are two plain text input 
            Assert.AreEqual(configUseCase.Screens[0].Panels[0].Controls[0].Quantity, 2);
            Assert.AreEqual(configUseCase.Screens[0].Panels[0].Controls[0].ControlPattern, ControlPattern.PlainTextInput);

            // Two check box
            Assert.AreEqual(configUseCase.Screens[0].Panels[0].Controls[1].Quantity, 2);
            Assert.AreEqual(configUseCase.Screens[0].Panels[0].Controls[1].ControlPattern, ControlPattern.CheckBox);

            // Three Radio Buttons
            Assert.AreEqual(configUseCase.Screens[0].Panels[0].Controls[2].Quantity, 1);
            Assert.AreEqual(configUseCase.Screens[0].Panels[0].Controls[2].ControlPattern, ControlPattern.RadioButton);

            // Two slider controls
            Assert.AreEqual(configUseCase.Screens[0].Panels[0].Controls[3].Quantity, 1);
            Assert.AreEqual(configUseCase.Screens[0].Panels[0].Controls[3].ControlPattern, ControlPattern.SlideControl);

            // One SmallListMultipleSelector
            Assert.AreEqual(configUseCase.Screens[0].Panels[0].Controls[4].Quantity, 1);
            Assert.AreEqual(configUseCase.Screens[0].Panels[0].Controls[4].ControlPattern, ControlPattern.SmallSetMultipleSelector);

        }
    }
}
